package codeTop;

public class q704 {
    public int search(int[] nums, int target) {
        int l = 0;
        int r = nums.length-1;
        while (l < r) {
            int mid = l+(r-l)/2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] > target) {
                r = mid -1;
            }else {
                l = mid+1;
            }
        }
        if (nums[l] != target) {
            return -1;
        }else {
            return l;
        }
    }

    public int binaryInsert(int[] nums,int target){
        int l = 0;
        int r = nums.length;
        while (l < r) {
            int mid = l+(r-l)/2;
            if (nums[mid] < target) {
                l = mid+1;
            }else {
                r = mid;
            }
        }
        return l;
    }
}
